package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.im.ECApplication;
import com.shengyuan.manage_os.old.ying.erpm.controls.CheLiangMingCheng;
import com.shengyuan.manage_os.old.ying.erpm.controls.CurrentTime;
import com.shengyuan.manage_os.old.ying.erpm.db.Actual_JiShi_Table;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;
import android.os.Bundle;

public class Actual_Form_TaiBanKaiShi_SL extends Actual_Form_TaiBanKaiShi_JX {

	
	@Override
	public String MyID() {
		return getClass().getName();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState, true);
		MainApplication.currentActivity = this;
		setContentView(R.layout.actual_form_taiban_ziyoushilun_kaishi);
		InitControls();
	}

	@Override
	protected void SaveJsonData() {
		IsJson1 = true; mFinished = 0;
		SaveData();
	}
	
	protected void SaveData(){
		try {
			JsonMyID();
			getCar();
			getTask();
			//getFuWuMingCheng();
			getCaiLiao();
			getZhongLiang();
			
			getGPS();
			getCurrentUser();		
			getMemo();
			JsonPicture();
			if (PictureButton_Km!=null) {
				mJson.put( PictureButton_Km.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_Km.mFileName);
			}
		}catch (Exception e) {
		}
	}
	
	protected void getCar() throws JSONException {
		if (CheLiangMingCheng.mMachinery!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_car), CheLiangMingCheng.mMachinery.Name);
		}
	}
	
	@Override
	protected void Save_Has_Finished() {
		if (mMaxid>0) {
	        Actual_JiShi_Table dbo= new Actual_JiShi_Table(this);
	        dbo.Save_FirstStartRecord(CheLiangMingCheng.mMachinery.Name, CurrentTime.getLongTime(), mMaxid);
	        dbo.close();
		}
	}

	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_Car, sPath);
			CopyPicDest(PictureButton_Chexing, sPath);
			CopyPicDest(PictureButton_Km, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	@Override
	public void Back() {
		if (view!=null) {
			view.postInvalidate();
		}
		super.Back();
	}
	@Override
	public Boolean IsPassed() {
		String value;
//		if (editText_gongyingshang!=null) {
//			value = editText_gongyingshang.getText().toString();
//			if (value.equals("")) {
//				Utility.MessageBox(editText_gongyingshang.getHint().toString());
//				return false;
//			}
//		}

		if (GpsButton_Gps.x ==0 && GpsButton_Gps.y==0) {
			Utility.MessageBox(this, GpsButton_Gps.hint );
			return false;
		}
		if (!PictureButton_Car.IsExist()) {
			Utility.MessageBox(this, PictureButton_Car.FIELD );
			return false;
		}			
		if (!PictureButton_Chexing.IsExist()) {
			Utility.MessageBox(this, PictureButton_Chexing.FIELD );
			return false;
		}		
		if (PictureButton_Km!=null && !PictureButton_Km.IsExist()) {
			Utility.MessageBox(this, PictureButton_Km.FIELD );
			return false;
		}
		return true;

	}

}
